#ifndef _LOG_HPP_
#define	_LOG_HPP_
/*******************************************************************************
 ** Government Sanctioned Espionage RPG                                       **
 ** http://www.government-sanctioned.us/                                      **
 **===========================================================================**
 ** Name: log.hpp                                                              **
 ** Description:                                           **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the LICENSE file within             **
 ** this distribution or at $WIKI/display/GOVT/License-software.              **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $GAME_DIR/LICENSE.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 ** Copyright (c) 2009-2012  Barry Gian James <gian@gamingods.net>            **
 ** All rights reserved.
 **                                                                           **
 ** Ref: $HeadURL$  **/
// Created on March 24, 2010, 1:02 AM
// Modified $Date$ by $Author$

#define Log_hpp_ID   "$Id$"

#include <fstream>
#include <string>
extern "C" {
#include <stdarg.h>
}
#include "common.hpp"

#define LOG_DATE    0x01
#define LOG_TIME    0x02
#define LOG_DATETIME 0x04
#define LOG_FUNC    0x08
#define LOG_LINE    0x10
#define LOG_DIR     "../data/"
#define LOG_DEBUG   1
#define LOG_INFO    2
#define LOG_IMPORT  3
#define LOG_CRIT    4
#define LOG_FATAL   5


//! Manages writing log files (including debug functionality)
class Log
{
public:
    Log(const std::string & fl);
    Log(const Log& orig) = delete;
    virtual ~Log();
    
    void    out(const char *, ...);
    void    out(int,const char *,...);

    bool    IsOK() const { return fileStream.is_open(); }
    int     SetFlag(int flag) { flags |= flag; return flags; }
    int     Flags() const { return flags; }
    uint8_t   Level(uint8_t l = 0) { if (l) level = l; return level; }

private:
    std::string    	fileName;
    bool            bIsOk;
    std::ofstream 	fileStream;
    int             flags;
    uint8_t         level;
};

namespace debug {
extern Log * log;
}

#endif	/* _LOG_HPP_ */

